package cn.kailangtu.serialutils.api;

public class InfraredManager {
    private int item1Value  = 0;
    private int item2Value = 0;
    private int item3Value = 0;


    InfraredMessageListener listener;

    static InfraredManager instance;
    public static InfraredManager getInstance(){
        if(instance == null)
        {
            instance = new InfraredManager();
        }
        return instance;
    }


    private InfraredManager(){

    }

    public void initListener(InfraredMessageListener listener){
        this.listener = listener;
    }

    public void onDiMessage(int itemNo,int action)
    {
        if(listener != null )
        {
            listener.onReceiveAction(itemNo,action,getActionMsg(action));
        }
    }

    private String getActionMsg(int action){
        if(action == 0)
        {
            return "无键值";
        }
        else if(action == 1){
            return "左";
        }
        else if(action == 2)
        {
            return "上";
        }
        else if(action == 2)
        {
            return "右";
        }
        else if(action == 2)
        {
            return "下";
        }
        else if(action == 2)
        {
            return "确认";
        }
        else if(action == 2)
        {
            return "取消";
        }
        return "";
    }

    public void newValue(int item1Value,int item2Value,int item3Value)
    {
        if(item1Value != this.item1Value)
        {
            this.item1Value = item1Value;
            onDiMessage(0,item1Value);
        }

        if(item2Value != this.item2Value)
        {
            this.item2Value = item2Value;
            onDiMessage(1,item2Value);
        }

        if(item3Value != this.item3Value)
        {
            this.item3Value = item3Value;
            onDiMessage(2,item3Value);
        }

    }
}
